package com.zz.controller;

import com.alibaba.fastjson.JSONObject;
import com.zz.service.*;
import com.zz.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 销售指标
@Slf4j
@RestController
@RequestMapping("/sale")
public class SaleController {

    @Autowired
    SaleService saleService;

    @Autowired
    SaleESignService saleESignService;

    @Autowired
    SaleChangeESignService changeESignService;

    @PostMapping("/getTemplate")
    public ResultUtil getTemplate(@RequestBody JSONObject jsonObject) {
        return saleService.getTemplate(jsonObject);
    }

    @PostMapping("/getChangeTemplate")
    public ResultUtil getChangeTemplate(@RequestBody JSONObject jsonObject) {
        return saleService.getChangeTemplate(jsonObject);
    }

    @PostMapping("/saleSignature")
    public ResultUtil saleSignature(@RequestBody JSONObject jsonObject) {
        String id = jsonObject.getString("id");
        String operationId = jsonObject.getString("operationId");
        return saleESignService.saleSignature(id, operationId);
    }


    @PostMapping("/saleCallBack")
    public String saleCallBack(@RequestBody String json) {
        // 接口e签宝的回调
        log.info("e签宝的合同回调json = " + json);
        saleESignService.saleCallBack(json);
        return "{\"code\":\"200\",\"msg\":\"success\"}";
    }

    @PostMapping("/saleChangeSignature")
    public ResultUtil saleChangeSignature(@RequestBody JSONObject jsonObject) {
        String id = jsonObject.getString("id");
        String operationId = jsonObject.getString("operationId");
        return changeESignService.saleChangeSignature(id, operationId);
    }


    @PostMapping("/saleChangeCallBack")
    public String saleChangeCallBack(@RequestBody String json) {
        // 接口e签宝的回调
        log.info("e签宝的合同回调json = " + json);
        changeESignService.saleChangeCallBack(json);
        return "{\"code\":\"200\",\"msg\":\"success\"}";
    }


    @GetMapping("/testSale")
    public void testSale() {
        saleESignService.updateSaleTarget("");
    }

    @GetMapping("/testSaleChange")
    public void testSaleChange(@RequestParam String targetHospitalId) {
        changeESignService.updateSaleTarget(targetHospitalId);
    }

}
